
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Test from '@/pages/Test'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// 普通模式引入路由组件
// import MyOrder from '@/pages/Center/MyOrder'
// 路由组件懒加载方式一 返回值是一个函数
// const MyOrder = ()=>import('@/pages/Center/MyOrder')
import GroupOrder from '@/pages/Center/GroupOrder'


export default [
    {
        path:'/center',
        component:Center,
        children:[
            {
                path:'myorder',
                // component:MyOrder
                // 路由组件懒加载方式二：
                component:()=>import('@/pages/Center/MyOrder')
            },
            {
                path:'grouporder',
                component:GroupOrder
            },
            {
                path:'',
                redirect:'myorder',
            }
        ]
    },
    {
        path:'/paysuccess',
        component:PaySuccess,
        beforeEnter: (to, from,next) => {
            // 只能从 支付页 以及跟路径(刷新的时候) / 进入该路由组件
            if(from.path.indexOf('/pay') !== -1 || from.path === '/'){
                next()
            }else{
                next(false)
            }
          },
    },
    {
        path:'/pay/:orderId?',
        component:Pay,
        beforeEnter: (to, from,next) => {
            // 只能从 提交订单页 以及跟路径(刷新的时候) / 进入该路由组件
            if(from.path.indexOf('/trade') !== -1 || from.path === '/'){
                next()
            }else{
                next(false)
            }
          },
    },
    {
        path:'/trade',
        component:Trade,
        beforeEnter: (to, from,next) => {
            // 只能从购物车 登录页 以及跟路径 / (刷新的时候) 进入该路由组件
            if(from.path.indexOf('/shopcart') !== -1 || from.path.indexOf('/login') !== -1 || from.path === '/'){
                next()
            }else{
                next(false)
            }
          },
    },
    {
        path:'/shopcart',
        component:ShopCart
    },
    {
        path:'/addcart_success',
        component:AddCartSuccess,
        name:'addcart_success'
    },
    {
        path:'/detail/:skuId?',
        component:Detail
    }
    ,
    {
        path:'/test',
        component:Test
    },
    {
        path:'/home',
        component:Home
    },
    {
        path:'/login',
        component:Login,
        // 设置meta属性，在根组件中用于条件渲染Footer组件
        meta:{
            isHidden:true
        }
    },
    {
        path:'/register',
        component:Register,
        meta:{
            isHidden:true
        }
    },
    {
        path:'/search/:keyword?',
        component:Search,
        name:'search',
        // 直接解构 params 和 query 所有参数，在组件中直接 props：['参数名'] 接收
        props:(route)=>({...route.params,...route.query})
    },
    {
        path:'/',
        redirect:'/home'
    }
]